# menu/views.py
from django.db.models import Q
from django.conf import settings
from django.contrib.auth import authenticate,login,logout
from django.contrib.auth.hashers import make_password
from django.contrib.auth.backends import ModelBackend

from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import viewsets
from rest_framework import serializers
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from rest_framework.permissions import DjangoModelPermissions
from django_filters.rest_framework import DjangoFilterBackend

from utils.pagination import CustomPageNumberPagination
from utils.generics import ListAPIView
from .models import Menu
from menu.serializers import MenuSerializer

# 菜单序列化
# class MenuResponseSerializer(serializers.Serializer):
# 	status = serializers.BooleanField()
# 	menu = MenuSerializer(many=True)

class MenuView(ListAPIView, GenericViewSet):

	"""获取左侧菜单"""
	queryset = Menu.objects.filter(parent__isnull=True)
	serializer_class = MenuSerializer
	# @swagger_auto_schema(
	# 	title='获取左侧菜单',
	# 	operation_description='获取左侧菜单',
	# 	responses={200: MenuResponseSerializer})

	# def get(self,request):
	# 	# 解决react ie cookie禁用问题
	# 	menu = Menu.objects.all()
	# 	return Response({'status':'ok', 'menu':MenuSerializer(menu, many=True).data})
